package mysql

var MysqlTpl = `
package db

import (
    "fmt"
    "gorm.io/driver/mysql"
    "gorm.io/gorm"
    "gorm.io/plugin/opentelemetry/tracing"
    "{{.App}}/pkg/storage/conf"
)

var (
    DB *gorm.DB
)

func Init() {
    c := conf.Cfg.Mysql
    var err error
    dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", c.User, c.Pwd, c.Host, c.Port, c.Databases)
    DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
    if err != nil {
        panic(err)
    }

    if err = DB.Use(tracing.NewPlugin(tracing.WithoutMetrics())); err != nil {
        panic(err)
    }

    fmt.Println("mysql连接成功")
}
`
